#include <bits/stdc++.h>
#define lowbit(x) (x&-x)
#define pii pair<int,int>
#define mk make_pair
#define fi first
#define se second
#define ll long long
using namespace std;

const int inf=1e9;
const int Maxn=5e5+7,Maxv=1e6+7;
int Q;
int ans[Maxn];
map<pii,int>mp;

int uans[Maxn<<2];
pii cap[Maxn<<2];
vector<pii >add[Maxn<<2];

class BIT1{
	public:
		int tr[Maxv],sz;
		int top;pii stk[Maxv*10];
		inline void add(int x,int k){
			while(x<=sz) stk[++top]=mk(x,tr[x]),tr[x]=max(tr[x],k),x+=lowbit(x);
		}
		inline int query(int x){
			int ret=0;
			while(x) ret=max(ret,tr[x]),x-=lowbit(x);
			return ret;
		}
}t1;
class BIT2{
	public:
		int tr[Maxv],sz;
		int top;pii stk[Maxv*10];
		inline void add(int x,int k){
			while(x) stk[++top]=mk(x,tr[x]),tr[x]=min(tr[x],k),x-=lowbit(x);
		}
		inline int query(int x){
			int ret=inf;
			while(x<=sz) ret=min(ret,tr[x]),x+=lowbit(x);
			return ret;
		}
}t2;

void Insert(int node,int l,int r,int L,int R,pii x){
	if(l>=L and r<=R){
		add[node].emplace_back(x);
		return ;
	}
	int mid=(l+r)>>1;
	if(L<=mid) Insert(node<<1,l,mid,L,R,x);
	if(R>mid) Insert(node<<1|1,mid+1,r,L,R,x);
}

inline pii Merge(pii x,pii y){
	if(!x.fi) return y; 
	if(!y.fi) return y;
	return mk(max(x.fi,y.fi),min(x.se,y.se));
}
int lsn[Maxv],rsn[Maxv];
pii stk1[Maxv],stk2[Maxv];
int top1,top2;
void solve(int node,int l,int r){
	int tp1=t1.top,tp2=t2.top,tp3=top1,tp4=top2;
	cap[node]=cap[node/2];
	uans[node]=uans[node/2];
	for(auto i:add[node]){
		cap[node]=Merge(cap[node],i);
		stk1[++top1]=mk(i.se,rsn[i.se]);
		stk2[++top2]=mk(i.fi,lsn[i.fi]);
		rsn[i.se]=max(rsn[i.se],i.fi);
		lsn[i.fi]=min(lsn[i.fi],i.se);
		
		int val1=t1.query(i.fi),val2=t2.query(i.se);
		if(val1) uans[node]=min(uans[node],i.se-val1);
		uans[node]=min(uans[node],val2-i.fi);
		t1.add(i.se,i.fi),t2.add(i.fi,i.se);
	}
	
	if(l==r){
		if(cap[node].fi<cap[node].se){
			ans[l]=lsn[cap[node].fi]-rsn[cap[node].se];
		}
		else{
			ans[l]=uans[node];
		}
		return ;
	}
	int mid=(l+r)>>1;
	solve(node<<1,l,mid),solve(node<<1|1,mid+1,r);
	
	while(top1>tp3) rsn[stk1[top1].fi]=stk1[top1].se,top1--;
	while(top2>tp4) lsn[stk2[top2].fi]=stk2[top2].se,top2--;
	while(t1.top>tp1){int u=t1.top;t1.tr[t1.stk[u].fi]=t1.stk[u].se;t1.top--;}
	while(t2.top>tp2){int u=t2.top;t2.tr[t2.stk[u].fi]=t2.stk[u].se;t2.top--;}
}

int main(){
	freopen("stone.in","r",stdin);
	freopen("stone.out","w",stdout);
	
	scanf("%d",&Q);
	int Vv=1e6;
	t1.sz=Vv,t2.sz=Vv;
	for(int i=1;i<=Vv;i++) lsn[i]=inf,t2.tr[i]=inf; 
	for(int i=0;i<=Q*4;i++) uans[i]=inf;
	for(int i=1;i<=Q;i++){
		char opt;int l,r; ans[i]=inf;
		cin>>opt;scanf("%d%d",&l,&r);
		if(opt=='A'){
			if(!mp[mk(l,r)]) mp[mk(l,r)]=i;
		}
		else{
			Insert(1,1,Q,mp[mk(l,r)],i-1,mk(l,r));
			mp[mk(l,r)]=0;
		}
	}
	for(auto i:mp) if(i.se!=0) Insert(1,1,Q,i.se,Q,i.fi);
	solve(1,1,Q);
	for(int i=1;i<=Q;i++) printf("%d\n",ans[i]);
	
	return 0;
}

